package edu.neumont.pro180._2009_q2;

import edu.neumont.pro180._2009_q2.interfaces.ICommand;
import edu.neumont.pro180._2009_q2.interfaces.IGamePiece;

public class GamePieceMove implements ICommand {
	protected Square destination, originalSquare;
	
	@Override
	public Square getDestination() {
		return destination;
	}
	
	@Override
	public Square getOriginalSquare() {
		return originalSquare;
	}

	public IGamePiece getToMove() {
		return toMove;
	}

	public IGamePiece getDisplaced() {
		return displaced;
	}

	protected IGamePiece toMove, displaced;

	@Override
	public void execute() {
		if (destination != null && destination.hasGamePiece()) {
			displaced = (IGamePiece)destination.getGamePiece();
		}
		toMove.setPosition(destination);
	}

	@Override
	public void undo() {
		toMove.setPosition(originalSquare);
		if (null != displaced) {
			displaced.setPosition(destination);
		}
	}

	public GamePieceMove(IGamePiece toMove, Square destination) {
		this.destination = destination;
		this.toMove = toMove;
		this.originalSquare = toMove.getSquare();
	}
	
	public GamePieceMove() {
		
	}
}
